import { createRouter, createWebHistory } from 'vue-router'

const routes = [
    /* 一级布局容器 */
    {
        path: '/',
        name: 'layout',
        component: () =>
            import ('@/views/Layout.vue'),
        children: [{
                path: '/',
                name: 'home',
                component: () =>
                    import ('@/views/home/index.vue'),
                redirect: 'recommended',
                children: [{
                        path: 'recommended',
                        name: 'recommended',
                        component: () =>
                            import ('@/views/home/recommended.vue')
                    },
                    {
                        path: 'following',
                        name: 'following',
                        component: () =>
                            import ('@/views/home/following.vue')
                    },
                    {
                        path: 'backend',
                        name: 'backend',
                        component: () =>
                            import ('@/views/home/backend.vue')
                    }
                ]
            },
            {
                path: '/pins',
                name: 'pins',
                component: () =>
                    import ('../views/pins/index.vue'),
            },
            {
                path: '/post',
                name: 'post',
                component: () =>
                    import ('../views/post/index.vue')
            }
        ]
    },
    {
        path: '/editor',
        name: 'editor',
        component: () =>
            import ('../views/editor/index.vue')
    }
]

const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes,
    scrollBehavior(to, from, savedPosition) {
        // 解决vue页面之间跳转，页面不是在顶部的问题
        return { left: 0, top: 0 }
    }
})

export default router